PROJECT_ROOT = ../../..
GMOCK_PATH = $(PROJECT_ROOT)/third_party/gmock
default: gjstest_main.a

# The directory compiled in to the tool as the default for built-in data files.
DEFAULT_DATA_DIR = $(PREFIX)/share/gjstest

# Tools and flags.
include $(PROJECT_ROOT)/tools.mk
CPPFLAGS += -DDEFAULT_DATA_DIR=$(DEFAULT_DATA_DIR)

UNAME := $(shell uname)

ifeq ($(UNAME), Linux)
# For clock_gettime in timer.cc.
CXXFLAGS += -lrt
endif

######################################################
# Libraries
######################################################

# Objects to include in the library.
LIB_OBJS = run_tests.o test_case.o v8_utils.o builtin_data.o
MAIN_OBJS = $(LIB_OBJS) gjstest_main.o

cpp.a : $(LIB_OBJS)
	rm -f $@
	$(AR) $(ARFLAGS) $@ $^

gjstest_main.a : $(MAIN_OBJS)
	rm -f $@
	$(AR) $(ARFLAGS) $@ $^

######################################################
# Tests
######################################################

# Additional objects to include in the test.
TEST_OBJS = v8_utils_test.o
TEST_DEPS = \
    $(GMOCK_PATH)/gmock_main.a \
    $(PROJECT_ROOT)/third_party/cityhash/cityhash.a \
    $(PROJECT_ROOT)/base/base.a \
    $(PROJECT_ROOT)/file/file.a \
    $(PROJECT_ROOT)/gjstest/internal/proto/proto.a \
    $(PROJECT_ROOT)/strings/strings.a \
    $(PROJECT_ROOT)/webutil/xml/xml.a \

v8_utils_test.bin : $(LIB_OBJS) $(TEST_OBJS) $(TEST_DEPS)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@ -lglog -lxml2 -lre2 -lprotobuf -lv8 -lgflags

test : v8_utils_test.bin
	./v8_utils_test.bin

######################################################
# House-keeping
######################################################

# depend target
OBJS = $(MAIN_OBJS) $(TEST_OBJS) $(LIB_OBJS)
include $(PROJECT_ROOT)/depend_target.mk

clean :
	rm -f *.o
	rm -f *.a

## Dependencies: (autogenerated) ##
run_tests.o: run_tests.cc ../../../gjstest/internal/cpp/run_tests.h \
  ../../../base/stl_decl.h ../../../base/stl_decl_osx.h \
  ../../../base/basictypes.h ../../../base/integral_types.h \
  ../../../base/integral_types.h ../../../base/logging.h \
  ../../../base/macros.h ../../../base/type_traits.h \
  ../../../base/template_util.h ../../../base/stl_decl.h \
  ../../../base/stringprintf.h ../../../base/timer.h \
  ../../../base/macros.h ../../../gjstest/internal/cpp/test_case.h \
  ../../../base/integral_types.h ../../../base/macros.h \
  ../../../gjstest/internal/cpp/v8_utils.h ../../../base/callback-types.h \
  ../../../base/callback.h ../../../base/logging.h \
  ../../../gjstest/internal/proto/named_scripts.pb.h \
  ../../../strings/strutil.h ../../../base/basictypes.h \
  ../../../util/gtl/map-util.h ../../../util/hash/hash.h \
  ../../../base/stl_decl.h ../../../third_party/cityhash/city.h \
  ../../../webutil/xml/xml_writer.h ../../../base/basictypes.h \
  ../../../base/macros.h
test_case.o: test_case.cc ../../../gjstest/internal/cpp/test_case.h \
  ../../../base/integral_types.h ../../../base/macros.h \
  ../../../base/type_traits.h ../../../base/template_util.h \
  ../../../base/stl_decl.h ../../../base/stl_decl_osx.h \
  ../../../base/callback.h ../../../base/logging.h \
  ../../../base/logging.h ../../../base/stringprintf.h \
  ../../../base/timer.h ../../../base/integral_types.h \
  ../../../base/macros.h ../../../gjstest/internal/cpp/v8_utils.h \
  ../../../base/callback-types.h ../../../base/callback.h
v8_utils.o: v8_utils.cc ../../../gjstest/internal/cpp/v8_utils.h \
  ../../../base/callback-types.h ../../../base/callback.h \
  ../../../base/logging.h ../../../base/integral_types.h \
  ../../../base/logging.h ../../../base/stringprintf.h
builtin_data.o: builtin_data.cc ../../../base/logging.h \
  ../../../file/file_utils.h ../../../base/basictypes.h \
  ../../../base/integral_types.h \
  ../../../gjstest/internal/cpp/builtin_data.h ../../../base/stl_decl.h \
  ../../../base/stl_decl_osx.h \
  ../../../gjstest/internal/proto/named_scripts.pb.h
gjstest_main.o: gjstest_main.cc ../../../base/integral_types.h \
  ../../../base/logging.h ../../../base/stringprintf.h \
  ../../../file/file_utils.h ../../../base/basictypes.h \
  ../../../base/integral_types.h \
  ../../../gjstest/internal/cpp/builtin_data.h ../../../base/stl_decl.h \
  ../../../base/stl_decl_osx.h ../../../gjstest/internal/cpp/run_tests.h \
  ../../../gjstest/internal/proto/named_scripts.pb.h \
  ../../../strings/strutil.h ../../../base/basictypes.h
v8_utils_test.o: v8_utils_test.cc \
  ../../../gjstest/internal/cpp/v8_utils.h ../../../base/callback-types.h \
  ../../../base/callback.h ../../../base/logging.h \
  ../../../base/callback.h ../../../base/integral_types.h \
  ../../../base/logging.h ../../../base/macros.h \
  ../../../base/type_traits.h ../../../base/template_util.h \
  ../../../third_party/gmock/include/gmock/gmock.h \
  ../../../third_party/gmock/include/gmock/gmock-actions.h \
  ../../../third_party/gmock/include/gmock/internal/gmock-internal-utils.h \
  ../../../third_party/gmock/include/gmock/internal/gmock-generated-internal-utils.h \
  ../../../third_party/gmock/include/gmock/internal/gmock-port.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-linked_ptr.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-port.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-port.h \
  ../../../third_party/gtest/include/gtest/gtest.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-internal.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-string.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-filepath.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-type-util.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-string.h \
  ../../../third_party/gtest/include/gtest/gtest-death-test.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-death-test-internal.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-internal.h \
  ../../../third_party/gtest/include/gtest/gtest-message.h \
  ../../../third_party/gtest/include/gtest/gtest-param-test.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-port.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-param-util.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-linked_ptr.h \
  ../../../third_party/gtest/include/gtest/gtest-printers.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-param-util-generated.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-param-util.h \
  ../../../third_party/gtest/include/gtest/gtest-printers.h \
  ../../../third_party/gtest/include/gtest/gtest_prod.h \
  ../../../third_party/gtest/include/gtest/gtest-test-part.h \
  ../../../third_party/gtest/include/gtest/gtest-typed-test.h \
  ../../../third_party/gtest/include/gtest/internal/gtest-type-util.h \
  ../../../third_party/gtest/include/gtest/gtest_pred_impl.h \
  ../../../third_party/gmock/include/gmock/internal/gmock-port.h \
  ../../../third_party/gmock/include/gmock/gmock-cardinalities.h \
  ../../../third_party/gtest/include/gtest/gtest.h \
  ../../../third_party/gmock/include/gmock/gmock-generated-actions.h \
  ../../../third_party/gmock/include/gmock/gmock-generated-function-mockers.h \
  ../../../third_party/gmock/include/gmock/gmock-spec-builders.h \
  ../../../third_party/gmock/include/gmock/gmock-matchers.h \
  ../../../third_party/gmock/include/gmock/gmock-generated-matchers.h \
  ../../../third_party/gmock/include/gmock/gmock-more-actions.h \
  ../../../third_party/gmock/include/gmock/gmock-generated-nice-strict.h \
  ../../../third_party/gtest/include/gtest/gtest.h
run_tests.o: run_tests.cc ../../../gjstest/internal/cpp/run_tests.h \
  ../../../base/stl_decl.h ../../../base/stl_decl_osx.h \
  ../../../base/basictypes.h ../../../base/integral_types.h \
  ../../../base/integral_types.h ../../../base/logging.h \
  ../../../base/macros.h ../../../base/type_traits.h \
  ../../../base/template_util.h ../../../base/stl_decl.h \
  ../../../base/stringprintf.h ../../../base/timer.h \
  ../../../base/macros.h ../../../gjstest/internal/cpp/test_case.h \
  ../../../base/integral_types.h ../../../base/macros.h \
  ../../../gjstest/internal/cpp/v8_utils.h ../../../base/callback-types.h \
  ../../../base/callback.h ../../../base/logging.h \
  ../../../gjstest/internal/proto/named_scripts.pb.h \
  ../../../strings/strutil.h ../../../base/basictypes.h \
  ../../../util/gtl/map-util.h ../../../util/hash/hash.h \
  ../../../base/stl_decl.h ../../../third_party/cityhash/city.h \
  ../../../webutil/xml/xml_writer.h ../../../base/basictypes.h \
  ../../../base/macros.h
test_case.o: test_case.cc ../../../gjstest/internal/cpp/test_case.h \
  ../../../base/integral_types.h ../../../base/macros.h \
  ../../../base/type_traits.h ../../../base/template_util.h \
  ../../../base/stl_decl.h ../../../base/stl_decl_osx.h \
  ../../../base/callback.h ../../../base/logging.h \
  ../../../base/logging.h ../../../base/stringprintf.h \
  ../../../base/timer.h ../../../base/integral_types.h \
  ../../../base/macros.h ../../../gjstest/internal/cpp/v8_utils.h \
  ../../../base/callback-types.h ../../../base/callback.h
v8_utils.o: v8_utils.cc ../../../gjstest/internal/cpp/v8_utils.h \
  ../../../base/callback-types.h ../../../base/callback.h \
  ../../../base/logging.h ../../../base/integral_types.h \
  ../../../base/logging.h ../../../base/stringprintf.h
builtin_data.o: builtin_data.cc ../../../base/logging.h \
  ../../../file/file_utils.h ../../../base/basictypes.h \
  ../../../base/integral_types.h \
  ../../../gjstest/internal/cpp/builtin_data.h ../../../base/stl_decl.h \
  ../../../base/stl_decl_osx.h \
  ../../../gjstest/internal/proto/named_scripts.pb.h
